package com.wdc.贪心;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("all")
public class E13Leetcode763 {

    public List<Integer> partitionLabels(String s) {
        ArrayList<Integer> result = new ArrayList<>();
        int[] edg = new int[26];
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            edg[chars[i] - 'a'] = i;
        }

        int index = 0;
        int end = -1;
        for (int i = 0; i < chars.length; i++) {
            index = Math.max(index, edg[chars[i] - 'a']);
            if (i == index) {
                result.add(i - end);
                end = i;
            }
        }

        return result;
    }
}
